home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / 1.6.0 / scripts / use2dot < prev   
Encoding:
Text File  |  2004-01-06  |  4.0 KB  |  114 lines

  1. #!/bin/sh
  2. # aside from this initial boilerplate, this is actually -*- scheme -*- code
  3. main='(module-ref (resolve-module '\''(scripts use2dot)) '\'main')'
  4. exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
  5. !#
  6. ;;; use2dot --- Display module dependencies as a DOT specification
  7.  
  8. ;;     Copyright (C) 2001 Free Software Foundation, Inc.
  9. ;;
  10. ;; This program is free software; you can redistribute it and/or
  11. ;; modify it under the terms of the GNU General Public License as
  12. ;; published by the Free Software Foundation; either version 2, or
  13. ;; (at your option) any later version.
  14. ;;
  15. ;; This program is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19. ;;
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with this software; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  23. ;; Boston, MA 02111-1307 USA
  24.  
  25. ;;; Author: Thien-Thi Nguyen
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; Usage: use2dot [OPTIONS] [FILE ...]
  30. ;; Display to stdout a DOT specification that describes module dependencies
  31. ;; in FILEs.
  32. ;;
  33. ;; A top-level `use-modules' form or a `:use-module' `define-module'-component
  34. ;; results in a "solid" style edge.
  35. ;;
  36. ;; An `:autoload' `define-module'-component results in a "dotted" style edge
  37. ;; with label "N" indicating that N names are responsible for triggering the
  38. ;; autoload.  [The "N" label is not implemented.]
  39. ;;
  40. ;; A top-level `load' or `primitive-load' form results in a a "bold" style
  41. ;; edge to a node named with either the file name if the `load' argument is a
  42. ;; string, or "[computed in FILE]" otherwise.
  43. ;;
  44. ;; Options:
  45. ;;  -m, --default-module MOD -- Set MOD as the default module (for top-level
  46. ;;                              `use-modules' forms that do not follow some
  47. ;;                              `define-module' form in a file).  MOD should be
  48. ;;                              be a list or `#f', in which case such top-level
  49. ;;                              `use-modules' forms are effectively ignored.
  50. ;;                              Default value: `(guile-user)'.
  51.  
  52. ;;; Code:
  53.  
  54. (define-module (scripts use2dot)
  55.   :autoload (ice-9 getopt-long) (getopt-long)
  56.   :use-module ((srfi srfi-13) :select (string-join))
  57.   :use-module ((scripts frisk)
  58.                :select (make-frisker edge-type edge-up edge-down))
  59.   :export (use2dot))
  60.  
  61. (define *default-module* '(guile-user))
  62.  
  63. (define (q s)                           ; quote
  64.   (format #f "~S" s))
  65.  
  66. (define (vv pairs)                      ; => ("var=val" ...)
  67.   (map (lambda (pair)
  68.          (format #f "~A=~A" (car pair) (cdr pair)))
  69.        pairs))
  70.  
  71. (define (>>header)
  72.   (format #t "digraph use2dot {\n")
  73.   (for-each (lambda (s) (format #t "  ~A;\n" s))
  74.             (vv `((label . ,(q "Guile Module Dependencies"))
  75.                   ;;(rankdir . LR)
  76.                   ;;(size . ,(q "7.5,10"))
  77.                   (ratio . fill)
  78.                   ;;(nodesep . ,(q "0.05"))
  79.                   ))))
  80.  
  81. (define (>>body edges)
  82.   (for-each
  83.    (lambda (edge)
  84.      (format #t "  \"~A\" -> \"~A\"" (edge-down edge) (edge-up edge))
  85.      (cond ((case (edge-type edge)
  86.               ((autoload) '((style . dotted) (fontsize . 5)))
  87.               ((computed) '((style . bold)))
  88.               (else #f))
  89.             => (lambda (etc)
  90.                  (format #t " [~A]" (string-join (vv etc) ",")))))
  91.      (format #t ";\n"))
  92.    edges))
  93.  
  94. (define (>>footer)
  95.   (format #t "}"))
  96.  
  97. (define (>> edges)
  98.   (>>header)
  99.   (>>body edges)
  100.   (>>footer))
  101.  
  102. (define (use2dot . args)
  103.   (let* ((parsed-args (getopt-long (cons "use2dot" args)    ;;; kludge
  104.                                    '((default-module
  105.                                        (single-char #\m) (value #t)))))
  106.          (=m (option-ref parsed-args 'default-module *default-module*))
  107.          (scan (make-frisker `(default-module . ,=m)))
  108.          (files (option-ref parsed-args '() '())))
  109.     (>> (reverse ((scan files) 'edges)))))
  110.  
  111. (define main use2dot)
  112.  
  113. ;;; use2dot ends here
  114.